package com.acme.bankapp.domain.account;

import java.util.Locale;

@SuppressWarnings("serial")
public class SavingAccount extends AbstractAccount {
	public SavingAccount(final double balance) {
		super(balance);
	}

	public void withdraw(double amount) throws NotEnoughFundsException {
		if (amount <= 0) {
			throw new IllegalArgumentException(MSG_AMOUNT_NONPOSITIVE);
		} else if (amount > balance) {
			throw new NotEnoughFundsException(amount, getMaximumAmountToWithdraw());
		} else {
			balance -= amount;
		}
	}

	public double getMaximumAmountToWithdraw() {
		return balance;
	}
	
	@Override
	public String toString() {
		return String.format(Locale.ENGLISH, "saving account with balance = %.2f", this.balance);
	}
}
